<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class PatentInfo extends MY_Controller {
	function __construct() { 
		parent::__construct();
		$this -> load -> model("Patent_data_model");	
	}



	//保存专利详情
	function savePatentData(){
	  $patentInfo=$this->load->database('patentInfo',true);//连接sqlserver 
	  $sql  = "select * from db_patent p left join db_patent_info i on p.patent_id=i.patent_id where p.status = 1 and i.status = 1";

	  $data1=$patentInfo->query($sql)->result_array();

	  if($data1){
	  	  $id = array();
		  	foreach ($data1 as $k => $v) {
		  		
			$connar['where']=$this->sqlEscape('title=?? and author=?? and patent_number=?? and announcement_date=?? and apply_date=?? and type=?? and identity=?? and owner=?? and status=?? and agent=?? and agent_dept=??',array($v['title'],$v['inventor'],$v['new_patent_id'],$v['authorize_time'],strtotime($v['applicationDate']),$v['type'],$v['admin_type'],$v['applicant'],$v['state'],$v['agent'],$v['agency']));

			//去掉重复的数据
			  $result = $this -> Patent_data_model -> get_list_full($connar);		
			  if(!$result){
					//添加
					$param['title'] = $v['title'];
					$param['author'] = $v['inventor'];
					$param['patent_number'] = $v['new_patent_id'];	
					$param['announcement_date'] = $v['authorize_time'];
					$param['apply_date'] = strtotime($v['applicationDate']);
					$param['type'] = $v['type'];
					$param['identity'] = $v['admin_type'];
					$param['owner'] = $v['applicant'];
					$param['status'] = $v['state'];
					$param['agent'] = $v['agent'];
					$param['agent_dept'] = $v['agency'];
					$param['created'] =  time();
					$id[] = $this -> Patent_data_model -> add($param);

			  	}				
		  	}
		  		
	  		exit("成功插入".count($id)."条数据");
	 	 }

	}
}